package com.xiaolin.ai;

import java.io.*;
import java.util.Scanner;

public class Main {
    public static void main(String[] args) {
        try {
            File file = new File("");
            ProcessBuilder p = new ProcessBuilder(file.getCanonicalPath() + "\\pbrain-pela.exe");
            Process app = p.start();
            PrintWriter outputWriter = new PrintWriter(app.getOutputStream(), true);
            BufferedReader bufferedReader = new BufferedReader(new InputStreamReader(app.getInputStream(), "GBK"));
            Scanner scanner = new Scanner(System.in);

            new Thread() {
                @Override
                public void run() {

                    try {
                        while (true){
                            String s = bufferedReader.readLine();
                            System.out.println(s);
                        }
                    } catch (Exception e) {
                        e.printStackTrace();
                    }

                }
            }.start();

            while (true) {
                String s = scanner.nextLine();
                if ("close".equals(s)) {
                    app.destroy();
                    System.exit(0);
                }
                outputWriter.println(s);
            }

        } catch (Exception e) {
            e.printStackTrace();
        }
    }



}
